package com.qifan.energy.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.qifan.energy.R;
import com.qifan.energy.bean.result.OrderItem;
import com.qifan.energy.global.GlideApp;
import com.qifan.energy.util.CheckUtil;

import java.util.List;

public class OrderReadyPayAdapter extends BaseQuickAdapter<OrderItem,BaseViewHolder> {

    public OrderReadyPayAdapter(@Nullable List<OrderItem> data) {
        super(R.layout.order_readypay_item, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, OrderItem item) {
        if (CheckUtil.hasContent(item.getOrderItemList())) {
            OrderItem.OrderItemListBean orderItemListBean = item.getOrderItemList().get(0);
            helper.addOnClickListener(R.id.cancel_order_tv).addOnClickListener(R.id.pay_order_tv);
            helper.setText(R.id.product_name_tv,orderItemListBean.getProductName())
                    .setText(R.id.price_tv,String.format("￥%.02f",orderItemListBean.getRealAmount()))
                    .setText(R.id.product_qulity_tv,String.format("共%d件商品 总计:",orderItemListBean.getProductQuantity()))
                    .setText(R.id.real_amount_tv,String.format("￥%.02f",orderItemListBean.getRealAmount()))
                    .setText(R.id.game_zeng_tv,String.format("游戏分%d",orderItemListBean.getGiftIntegration()))
                    .setText(R.id.game_zeng_tv,String.format("时间卡%.02f",orderItemListBean.getGiftTimeCard()))
                    .setText(R.id.coupon_zeng_tv,String.format("优惠券%.02f",orderItemListBean.getGiftCouponAmount()));
            ImageView productIv = helper.getView(R.id.product_iv);
            GlideApp.with(helper.itemView)
                    .load(orderItemListBean.getProductPic())
                    .placeholder(R.mipmap.icon_default_rect)
                    .error(R.mipmap.icon_default_rect)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(productIv);
        }
    }
}
